package com.elong.businesstravel.modules.home.dialog;

import java.util.ArrayList;
import java.util.List;

import com.elong.businesstravel.R;
import com.elong.businesstravel.base.view.TitleNavBarView;
import com.elong.businesstravel.modules.home.adapter.SimpleListAdapter;
import com.elong.businesstravel.modules.home.adapter.SimpleListDialogAdapter;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class ArrivalHotelDateDialog extends Dialog {

	private Context mContext;
	private ListView mListView;
	private SimpleListDialogAdapter mSimpleListAdapter;
	private OnItemClickListener mOnItemClickListener;
	private String mSelect;
	/** 房间保留到 */
	private List<String> mArrayArrival = new ArrayList<String>();

	public ArrivalHotelDateDialog(Context context) {
		super(context);
		init(context);
	}

	public ArrivalHotelDateDialog(Context context, int theme,
			List<String> arrayArrival, String select) {
		super(context, theme);
		mSelect = select;
		mArrayArrival = arrayArrival;
		init(context);
	}

	public ArrivalHotelDateDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		init(context);
	}

	protected void init(Context context) {
		mContext = context;
		Window window = getWindow();
		window.setGravity(Gravity.BOTTOM);
		setContentView(R.layout.dialog_arrival_hotel_date);

		mListView = (ListView) findViewById(R.id.listView);
		mSimpleListAdapter = new SimpleListDialogAdapter(mContext, mArrayArrival,
				mSelect);
		mListView.setAdapter(mSimpleListAdapter);

		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// Intent intent = new Intent();
				// intent.putExtra("position", arg2);
				// // setResult(RESULT_OK, intent);
				// // finish();
				if (null != mOnItemClickListener) {
					mOnItemClickListener.onItemClick(arg0, arg1, arg2, arg3);
				}
			}
		});
		setCanceledOnTouchOutside(true);
		setTitleNavBar();
	}

	protected void setTitleNavBar() {
		TitleNavBarView titleNavBarView = (TitleNavBarView) findViewById(R.id.titleNavBarView);
		titleNavBarView.setMessage("保留时间");
		titleNavBarView.setTitleBackground(R.color.bg_title_dialog);
		titleNavBarView.setLeftButtonImageString(0, "取消", R.color.text_blue);
		titleNavBarView
				.setLeftButtonOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						cancel();
					}
				});
		titleNavBarView.setRightButtonVisibility(View.INVISIBLE);
	}

	public void setOnItemListener(OnItemClickListener onItemClickListener) {
		mOnItemClickListener = onItemClickListener;
	}
}
